package com.more.spring.boot.springbootredisdemo.controller;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Redis原生API:
 * redisTemplate.opsForValue():操作String
 * redisTemplate.opsForHash():操作Hash
 * redisTemplate.opsForList():操作List
 * redisTemplate.opsForSet():操作Set
 * redisTemplate.opsForZSet():操作Sorted Set
 */
@RestController
public class RedisController {

    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping("/redis/setAndGet")
    @ResponseBody
    public String setAndGetValue(String name, String value){
        //添加字符串类型
        redisTemplate.opsForValue().set(name, value);

        return (String) redisTemplate.opsForValue().get(name);
    }
}
